package com.forum.controller.user;

import com.forum.dto.UserDTO;
import com.forum.entity.User;
import com.forum.result.Result;
import com.forum.server.UserService;
import com.forum.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @date: 2023/11/7 13:20
 * @author: hongdou
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 登录功能
     * @param userDTO
     * @return
     */
    @PostMapping("/login")
    public Result<UserVo> login(UserDTO userDTO){
        User user = userService.login(userDTO);

        UserVo userVo = UserVo.builder()
                .id(user.getId())
                .name(user.getName())
                .image(user.getImage())
                .token("123454")
                .build();
        return Result.success(userVo);
    }
}
